new Vue({
  el: "#app",
  data() {
    return {
      Domain_Business: "https://www.kdddy.cn/Image/",
      form: {
        Data: "company_honors", //状态
        Primary_Key: "",
        Primary_Key_Name: "Company_Honors_Name",
        isVague: true,
        Row_Status: "2",
        page: 1, //页数
        limit: 10, //每页数据条数
      },
      tableData: [], //表格数据
      total: 1,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    onSerach() {
      console.log(this.form.Primary_Key);

      //查询方法
      this.form.page = 1;
      this.getList(this.form.Primary_Key);
    },
    Add() {
      window.location.href = "./Add.html";
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      console.log(data);
      if (data == undefined) {
        data = "";
      }
      //换页方法
      let _this = this;
      $.ajax({
        type: "POST",
        // url: DomainName + "/getTableInquiryAction?token=" + $.cookie("token"),
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "company_honors", //表名
          Condition:
            "Row_Status !='2'AND Company_Honors_Name LIKE '%" + data + "%'",
        },
        // complete: function (XMLHttpRequest) {
        //   _this.loading = false
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        success: function (Result) {
          console.log(Result);

          _this.tableData = Result; //将获取的数据存到表格数据中
          _this.total = Number(Result.limit);
        },
        dataType: "json",
      });
    },
    Edit(Company_Honors_SerialNumber) {
      console.log(Company_Honors_SerialNumber);

      sessionStorage.setItem(
        "Company_Honors_SerialNumber",
        Company_Honors_SerialNumber
      );
      window.location.href =
        "./Edit.html?Company_Honors_SerialNumber=" +
        Company_Honors_SerialNumber;
    },
    Delete(index, row) {
      console.log(row);
      row.Row_Status = "2";
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_company_honors = new Object();
      lJSONObject_company_honors.company_honors = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_company_honors; //换表
      // return;
      const _this = this;
      this.$confirm("警告！此操作将删除该资质, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $.ajax({
            // url: DomainName + "/DeleteAction?token=" + $.cookie("token"),
            url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
            type: "POST",
            data: {
              Data: JSON.stringify(lJSONObject_DataSet),
            },
            success: function (res) {
              if (res.Status === "success") {
                _this.$message({
                  message: "删除成功",
                  type: "success",
                });
                _this.tableData.splice(index, 1);
              }
            },
            complete: function (XMLHttpRequest) {
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href =
                  absolutepath() +
                  XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            },
          });
        })
        .catch(() => {
          this.$message({
            type: "warning",
            message: "已取消操作",
          });
        });
    },
    Status(index, row) {
      console.log(row);
      if (row.Row_Status == 0) {
        row.Row_Status = 1;
      } else if (row.Row_Status == 1) {
        row.Row_Status = 0;
      }
      console.log(row);
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_company_honors = new Object();
      lJSONObject_company_honors.company_honors = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_company_honors; //换表
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          console.log(row);
          if (row.Row_Status == 0) {
            _this.$message({
              message: "展示成功",
              type: "success",
            });
          } else {
            _this.$message({
              message: "隐藏成功",
              type: "success",
            });
          }
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
      return;
      let obj = deepClone(row);
      obj.Row_Status = obj.Row_Status == "0" ? "1" : "0";
      $.ajax({
        url: DomainName + "/getEditAction?token=" + $.cookie("token"),
        type: "POST",
        data: {
          Data: JSON.stringify({ Modify: { company_honors: [obj] } }),
          Operation_Name: row.Row_Status == "0" ? "隐藏资质" : "展示资质",
        },
        success: function (res) {
          if (res.Status == "success") {
            _this.$message({
              type: "success",
              message: row.Row_Status == "0" ? "隐藏成功" : "展示成功",
            });
            _this.getList(_this.form);
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
      });
    },
  },
});
